import pymssql
import cx_Oracle as oracle
import pandas as pd
import numpy as np
import influxdb
import dateutil.parser as dtparser
from sklearn.metrics import r2_score

def loadDataFromTxt(filename,mycolumns):
    data=np.loadtxt(filename,dtype=str,delimiter=',')
    data=pd.DataFrame(data,columns=mycolumns)
    return data
    pass




factorColumns=['EMABuyForce15', 'EMABuySellAmountWeightedPressure1_10_80', 'EMABuySellPress1_10', 'EMABuySellVolumeWeightedPressure1_10_80', 'EMASellForce15', 'amplitude',
 'buyAverageAmountWeighted1_10_80', 'buyAverageVolume1_10', 'buyAverageVolumeWeighted1_10_80', 'buyForce', 'buyForcePrice', 'buyForcePriceRatio', 'buySellAmountWeightedPressure1_10_80',
 'buySellForceChange', 'buySellPress1_10', 'buySellVolumeRatio10', 'buySellVolumeRatio2', 'buySellVolumeRatio5', 'buySellVolumeWeightedPressure1_10_80',
 'buySellWeightedVolumeRatio10', 'buySellWeightedVolumeRatio2', 'buySellWeightedVolumeRatio5', 'buyWeightedVolume10', 'buyWeightedVolume2', 'buyWeightedVolume5',
 'differenceHighLow3m', 'increaseToday', 'logbuySellSpread', 'midIncreaseToBV3m', 'midMomentum', 'midPriceBV3m', 'midPriceIncreasePrevious1m',
 'midPriceIncreasePrevious2m', 'midPriceIncreasePrevious3m', 'midPriceIncreasePrevious5m', 'midSpeed', 'midStd60', 'midToVwap', 'midToVwap3m',
 'ratio', 'sellAverageAmountWeighted1_10_80', 'sellAverageVolume1_10', 'sellAverageVolumeWeighted1_10_80', 'sellForce',
 'sellForcePrice', 'sellForcePriceRatio', 'sellWeightedVolume10', 'sellWeightedVolume2',
 'sellWeightedVolume5', 'speed', 'volumeIncreaseMA100', 'volumeIncreaseMA100ToMean',
 'volumeIncreaseMA20', 'volumeIncreaseMA200', 'volumeIncreaseMA200ToMean', 'volumeIncreaseMA20ToMean',
 'volumeIncreaseMA3', 'volumeIncreaseMA3ToMean', 'volumeIncreaseMA40', 'volumeIncreaseMA40ToMean',
 'volumeIncreaseMeanLog', 'volumeMagnification10_30', 'vwap100ticks', 'vwap200ticks',
 'vwap20ticks', 'vwap3m', 'vwap3ticks', 'vwap3ticksToVwap100ticks', 'vwap3ticksToVwap200ticks',
 'vwap3ticksToVwap20ticks', 'vwap3ticksToVwap40ticks', 'vwap40ticks', 'vwapToday','midPrice'
 ]
totalColumns=['code','date','ttime','index','EMABuyForce15', 'EMABuySellAmountWeightedPressure1_10_80', 'EMABuySellPress1_10', 'EMABuySellVolumeWeightedPressure1_10_80', 'EMASellForce15', 'amplitude',
 'buyAverageAmountWeighted1_10_80', 'buyAverageVolume1_10', 'buyAverageVolumeWeighted1_10_80', 'buyForce', 'buyForcePrice', 'buyForcePriceRatio', 'buySellAmountWeightedPressure1_10_80',
 'buySellForceChange', 'buySellPress1_10', 'buySellVolumeRatio10', 'buySellVolumeRatio2', 'buySellVolumeRatio5', 'buySellVolumeWeightedPressure1_10_80',
 'buySellWeightedVolumeRatio10', 'buySellWeightedVolumeRatio2', 'buySellWeightedVolumeRatio5', 'buyWeightedVolume10', 'buyWeightedVolume2', 'buyWeightedVolume5',
 'differenceHighLow3m', 'increaseToday', 'logbuySellSpread', 'midIncreaseToBV3m', 'midMomentum', 'midPriceBV3m', 'midPriceIncreasePrevious1m',
 'midPriceIncreasePrevious2m', 'midPriceIncreasePrevious3m', 'midPriceIncreasePrevious5m', 'midSpeed', 'midStd60', 'midToVwap', 'midToVwap3m',
 'ratio', 'sellAverageAmountWeighted1_10_80', 'sellAverageVolume1_10', 'sellAverageVolumeWeighted1_10_80', 'sellForce',
 'sellForcePrice', 'sellForcePriceRatio', 'sellWeightedVolume10', 'sellWeightedVolume2',
 'sellWeightedVolume5', 'speed', 'volumeIncreaseMA100', 'volumeIncreaseMA100ToMean',
 'volumeIncreaseMA20', 'volumeIncreaseMA200', 'volumeIncreaseMA200ToMean', 'volumeIncreaseMA20ToMean',
 'volumeIncreaseMA3', 'volumeIncreaseMA3ToMean', 'volumeIncreaseMA40', 'volumeIncreaseMA40ToMean',
 'volumeIncreaseMeanLog', 'volumeMagnification10_30', 'vwap100ticks', 'vwap200ticks',
 'vwap20ticks', 'vwap3m', 'vwap3ticks', 'vwap3ticksToVwap100ticks', 'vwap3ticksToVwap200ticks',
 'vwap3ticksToVwap20ticks', 'vwap3ticksToVwap40ticks', 'vwap40ticks', 'vwapToday','midPrice','max1m','max2m','max5m','min1m','min2m','min5m','totalamount','totalvolume','amountIncrease','volumeIncrease','cross','volumeIncreaseMean','realData','crossBasisSize','corssBasisLast','crossBasisPosSize','crossBasisPosLast','crossSize','corssLast','crossPosSize','crossPosLast','amplitudeSize','amplitudeLast','emaAmplitudeSize','eamAmplitudeLast']

tickColumns=['code','date','tick', 'lastPrice','S1','S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9','S10','B1','B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9','B10','SV1','SV2', 'SV3', 'SV4', 'SV5', 'SV6', 'SV7', 'SV8', 'SV9','SV10', 'BV1','BV2', 'BV3', 'BV4', 'BV5', 'BV6', 'BV7', 'BV8', 'BV9','BV10','hp','lp','highLimit','lowLimit','volume','amount','dailyOpen','dailyPreClose','transactions_count','weightedAvgBid','weightedAvgAsk','total_bid_size','total_ask_size','peration1','peration2']

lastMarketDataPath=f'recordData/yesterdayMarketData/20200114/000001.SZ.txt'
todayMarketDataPath=f'recordData/marketData/20200115/000001.SZ.txt'
factorDataPath=f'recordData/factorData/20200115/000001.SZ.txt'

data=loadDataFromTxt(lastMarketDataPath,tickColumns)
#data=loadDataFromTxt(todayMarketDataPath,tickColumns)



